package edu.westga.cs.recommender.controller;

import java.util.LinkedList;

import edu.westga.cs.recommender.model.*;
import edu.westga.cs.recommender.model.datatypes.*;

/**
 * The main controller class for this application.
 * 
 * While it may need to be customized depending on changes to underlying database implementation,
 * do so with care.  Otherwise, it handles any type of items provided the correct input is made.
 * @author Brent W. Ezell
 *
 */
public class MainController {
	//Fields
	/**
	 * Field for the RetrieveInfo object for this controller.
	 */
	private RetrieveInfo info;
	/**
	 * Field for the RetrieveMatches object for this controller.
	 */
	private RetrieveMatches matches;
	
	//Constructor
	/**
	 * Initializes the class.
	 */
	public MainController() {
		this.info = new RetrieveInfo(); 
	}
	
	//Methods
	/**
	 * Gets a user's information based on input.
	 * @param login A string containing the login of the user to retrieve.
	 * @return A User object holding the user data.
	 */
	public User getUser(String login) {
		User match = this.info.retrieveUser(login);
		return match;
	}
	
	/**
	 * Gets a specific profile in response to input.
	 * @param login A string containing the login of the user owning the profile.
	 * @param profile A string containing the name of the profile to retrieve.
	 * @return A Profile object holding the relevant information.
	 */
	public Profile getProfile(String login, String profile) {
		LinkedList<String> tags = this.info.retrieveProfileTags(login, profile);
		Profile match = new Profile(login, profile, tags);
		return match;
	}
	
	/**
	 * Makes a new profile based on a raw search.
	 * @param login A string containing the login of the user making the search.
	 * @param tags A LinkedList<String> containing the tags to search on.
	 * @return A Profile object holding the temporary profile. 
	 */
	public Profile makeProfile(String login, LinkedList<String> tags) {
		Profile match = new Profile(login, "New Search", tags);
		return match;
	}
	
	/**
	 * Calls the RetrieveMatches class to handle retrieving items matching a given profile.
	 * @param profile The profile to search for matches on.
	 * @return A LinkedList<Item> containing the matching items.
	 */
	public LinkedList<Item> getItems(Profile profile) {
		this.matches = new RetrieveMatches(info);
		LinkedList<Item> items = this.matches.getItems(profile);
		return items;
	}
}
